package com.itboye.eweilisten.util.widget;

import android.app.ActionBar;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.itboye.eweilisten.R;

/**
 * Created by itboye on 2017/3/6.
 *
 * 性别设置
 */

public class SexPopupWindow extends PopupWindow {
    private TextView boy_tv, girl_tv,secrecy_tv, sex_cancel_tv;
    private View sexMenuView;

    public SexPopupWindow(Activity context, View.OnClickListener itemOnclick) {
        super(context);
        LayoutInflater layoutInflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        sexMenuView = layoutInflater.inflate(R.layout.sex_alert_dialog, null);
        boy_tv = (TextView) sexMenuView.findViewById(R.id.boy_tv);
        girl_tv = (TextView) sexMenuView.findViewById(R.id.girl_tv);
        secrecy_tv = (TextView) sexMenuView.findViewById(R.id.secrecy_tv);
        sex_cancel_tv = (TextView) sexMenuView.findViewById(R.id.sex_cancel_tv);

        sex_cancel_tv.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                dismiss();// ȡ��
            }
        });
        boy_tv.setOnClickListener(itemOnclick);
        girl_tv.setOnClickListener(itemOnclick);
        secrecy_tv.setOnClickListener(itemOnclick);
        this.setContentView(sexMenuView);
        this.setWidth(ActionBar.LayoutParams.FILL_PARENT);
        this.setHeight(ActionBar.LayoutParams.WRAP_CONTENT);
        this.setFocusable(true);
        this.setAnimationStyle(R.style.AnimBottom);
        ColorDrawable dw = new ColorDrawable(0xb000000);
        this.setBackgroundDrawable(dw);
        sexMenuView.setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                int height = sexMenuView.findViewById(R.id.sex_layout).getTop();
                int y = (int) event.getY();
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    if (y < height) {
                        dismiss();
                    }
                }

                return true;
            }
        });
    }
}
